package com.situ.mall.manager.controller.api;


import com.situ.mall.manager.entity.Result;
import com.situ.mall.manager.util.UploadUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

//文件上传的controller
@RestController
@RequestMapping("/api/upload")
public class APIUploadController {

    @Value("${upload.path}")
    private String path;    //使用spring的el表达式，读取配置文件中upload.path属性的值

    //上传文件的操作应该使用POST请求
    @PostMapping
    public Result upload(MultipartFile file){
        String fileName = UploadUtil.save(file,path);
        if(fileName != null){
            return Result.success(fileName);
        }else{
            return Result.error("上传失败");
        }



    }

}
